id/email
password
forgot password | create account
about | help | prefs
ReadingBatcode reading practice

 

 

Warmup 1StringLength

prev  |  next  |  chance
public static int examine(String str) {
    int c = 0;

    if (str.length() < 2)
        return -1;

    for (int i = 0; i < str.length(); i++)
        if (str.substring(i, i + 1).equals("a"))
            c++;

    return c;
}
Function Call  Return Value
examine("aaabbb")
examine("bbba")
examine("aa")
examine("a")
examine("")
examine("hello")

Experiment with this code on Gitpod.io

Work on a similar problem on CodingBat.com

⬅ Back